import html2canvas from "html2canvas";

export const base64toImg = {
  data() {
    return {
      ydLoading: false
    }
  },
  methods: {
    //  单选转疑点
    addYd(record, ydnr, time) {
      this.ydLoading = !ydnr
      html2canvas(this.$refs.imageWrapper).then(canvas => {
        let dataURL = canvas.toDataURL("image/png");
        this.$refs.YDModel.show(record, dataURL, ydnr, time)
        this.ydLoading = false
      });
    },
    // 多选转疑点
    addYdMulti(record, ydnr, time, gzzd) {
      this.ydLoading = true
      html2canvas(this.$refs.imageWrapper).then((canvas) => {
        let dataURL = canvas.toDataURL('image/png')
        console.log('父组件调用完了')
        this.$refs.YDModel.show(record, dataURL, ydnr, time, gzzd)
        this.ydLoading = false
      })
    },
    dataURLtoFile(dataurl, filename) {
      //将base64转换为文件
      var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
      }
      return new File([u8arr], filename, { type: mime });
    }
  }

}